package vn.allmobile.newsreader;

import java.util.ArrayList;
import java.util.List;

import vn.allmobile.newsreader.adapters.CategoryAdapter;
import vn.allmobile.newsreader.data.Category;
import vn.allmobile.newsreader.data.Paper;
import vn.allmobile.newsreader.utils.Contants;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.jess.ui.TwoWayAdapterView;
import com.jess.ui.TwoWayAdapterView.OnItemClickListener;
import com.jess.ui.TwoWayGridView;

public class CategoriesActivity extends Activity {

	String mSourceID = "";
	Paper mPaper;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Get Paper
		this.mPaper = Contants.PAPER_PASS_TO_CATEGORYACTIVITY;
		setContentView(R.layout.categories_activty);
		TwoWayGridView mGridView = (TwoWayGridView) this
				.findViewById(R.id.category_gridview);
		CategoryAdapter mAdapter = new CategoryAdapter(getApplicationContext(),
				mPaper.getCategories());
		mGridView.setAdapter(mAdapter);

		mGridView.setOnItemClickListener(onItemClick);

	}

	private OnItemClickListener onItemClick = new OnItemClickListener() {

		@Override
		public void onItemClick(TwoWayAdapterView<?> parent, View view,
				int position, long id) {
			List keyList = new ArrayList(mPaper.getCategories().keySet());
			Object mKey = keyList.get(position);
			Category mCategory = mPaper.getCategories().get(mKey);
			Contants.CATEGORY_PASSTO_NEWSACTIVITY = mCategory;
			Intent mIntent = new Intent(getApplicationContext(),
					NewsActivity.class);
			startActivity(mIntent);
		}
	};

}
